/*
package com.fyl.utils;


import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;

import java.util.Arrays;

*/
/**
 * Author：Mr.X
 * Date：2017/11/8 10:00
 * Description：
 *//*

@Component
public class SpringContextUtils implements ApplicationContextAware {

    */
/**
     * 上下文对象实例
     *//*

    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        if (SpringContextUtils.applicationContext == null) {
            SpringContextUtils.applicationContext = applicationContext;
        }
    }

    */
/**
     * 获取applicationContext
     *
     * @return
     *//*

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    */
/**
     * 通过name获取 Bean.
     *
     * @param name
     * @return
     *//*

    public static Object getBean(String name) {
        return getApplicationContext().getBean(name);
    }

    */
/**
     * 通过class获取Bean.
     *
     * @param clazz
     * @param <T>
     * @return
     *//*

    public static <T> T getBean(Class<T> clazz) {
        return getApplicationContext().getBean(clazz);
    }

    */
/**
     * 通过name,以及Clazz返回指定的Bean
     *
     * @param name
     * @param clazz
     * @param <T>
     * @return
     *//*

    public static <T> T getBean(String name, Class<T> clazz) {
        return getApplicationContext().getBean(name, clazz);
    }


    public static Object registerBeanIfAbsent(String clazz) throws IllegalAccessException, InstantiationException, ClassNotFoundException {
        Class<?> clz = Class.forName(clazz);
        Object bean = null;
        try {
            bean = SpringContextUtils.getBean(clz);
        } catch (Exception e) {
            //todo
        }
        if (null != bean) {
            return bean;
        }
        bean = clz.newInstance();

        //将applicationContext转换为ConfigurableApplicationContext
        ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) applicationContext;
        // 获取bean工厂并转换为DefaultListableBeanFactory
        DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) configurableApplicationContext.getBeanFactory();

        // 属性自动注入 BeanFactory
        AutowireCapableBeanFactory autowireCapableBeanFactory = configurableApplicationContext.getAutowireCapableBeanFactory();

        // 注入到容器中
        String springId = SpringContextUtils.toLowerCaseFirstOne(clz.getSimpleName());
        defaultListableBeanFactory.registerSingleton(springId, bean);
        // 属性注入
        autowireCapableBeanFactory.autowireBean(bean);
        return bean;

    }


    //首字母转小写
    public static String toLowerCaseFirstOne(String s) {
        if (Character.isLowerCase(s.charAt(0)))
            return s;
        else {
            return (new StringBuilder()).append(Character.toLowerCase(s.charAt(0))).append(s.substring(1)).toString();
        }
    }

}
*/
